package xyz.lne.researchgroupmanage.security;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.GrantedAuthority;
import xyz.lne.researchgroupmanage.service.dataTransferObject.ResearchGroupSimpleDTO;
import xyz.lne.researchgroupmanage.service.dataTransferObject.ResearchSimpleDTO;
import xyz.lne.researchgroupmanage.service.dataTransferObject.TaskSimpleDTO;

/**
 * Designed By Lne.
 * 2021/1/28 15:41
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserAuthority implements GrantedAuthority {
    private String power;
    private Integer id;

    public static UserAuthority researchManage(ResearchSimpleDTO researchSimpleDTO){
        return new UserAuthority(UserPower.RESEARCH_MANAGE, researchSimpleDTO.getResearchId());
    }

    public static UserAuthority researchJoin(ResearchSimpleDTO researchSimpleDTO){
        return new UserAuthority(UserPower.RESEARCH_JOIN, researchSimpleDTO.getResearchId());
    }

    public static UserAuthority researchGroupManage(ResearchGroupSimpleDTO researchGroupSimpleDTO){
        return new UserAuthority(UserPower.RESEARCH_GROUP_MANAGE, researchGroupSimpleDTO.getResearchgroupId());
    }

    public static UserAuthority researchGroupJoin(ResearchGroupSimpleDTO researchGroupSimpleDTO){
        return new UserAuthority(UserPower.RESEARCH_GROUP_JOIN, researchGroupSimpleDTO.getResearchgroupId());
    }

    public static UserAuthority participateTask(TaskSimpleDTO taskSimpleDTO){
        return new UserAuthority(UserPower.PARTICIPATE_TASK, taskSimpleDTO.getTaskId());
    }

    @Override
    public String getAuthority() {
        return power + id;
    }
}
